#!/bin/sh

set -e

APP_NAME=$1
VERSION="develop"
NETWORK="chess_game_develop"
LOCAL_CONFIG_NAME="测试服"
LOCAL_WAN_IP="116.62.150.140"
VOLUTE1="/root/project/chess_game/develop/config:/root/app/config"
VOLUTE2="/root/project/chess_game/develop/log:/root/app/log"

# 名称检测
case "$APP_NAME" in
  "all")
    ;;
  "demo")
    ;;
  *) echo "名称错误:$APP_NAME"
    exit 1
    ;;
esac

# 参数
REGISTRY=registry.cn-hangzhou.aliyuncs.com
REGISTRY_NAMESPACE=fattigerlee
REGISTRY_USER=505179140@qq.com
REGISTRY_PASSWORD=C317t#VrjAb*r%uv

# 登录docker
docker login -u $REGISTRY_USER -p $REGISTRY_PASSWORD $REGISTRY

# 清理无用的镜像和容器
docker image prune -f
docker container prune -f

# 运行容器
if [ "$APP_NAME" = "demo" ]; then
  IMAGE_NAME=$REGISTRY/$REGISTRY_NAMESPACE/demo
  docker pull $IMAGE_NAME:$VERSION
  
  NAME="${VERSION}_demo"
  docker run -d -p 80:80 --name $NAME --network $NETWORK --ip 172.18.0.3 $IMAGE_NAME:$VERSION
fi